 package com.e2e.haiti.infrastructure.surveyor;


import java.lang.reflect.Array;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.TimeZone;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.database.sqlite.SQLiteQueryBuilder;
import android.database.sqlite.SQLiteStatement;
import android.util.Log;

public class SqlHelper extends SQLiteOpenHelper {
    private static final String DATABASE_PATH = "/data/data/com.e2e.haiti.infrastructure.surveyor/databases/";

    public static final String DATABASE_NAME = "Haiti_Infrastructure_Surveyor";

    public static final String TABLE_NAME = "Structures";
    public static final int StructureItems_VERSION = 5;

    // Listview item details for each structure
    public static final String COLUMN_ID = "_id";               // 0
    public static final String COLUMN_SURVEYOR_NAME = "surveyorName";          // 1
    public static final String COLUMN_STRUCTURE_NAME = "structureName";          // 1
    public static final String COLUMN_STRUCTURE_DESC = "structureDesc";// 2
    public static final String COLUMN_STRUCTURE_STATUS= "structureStatus";// 3
    public static final String COLUMN_STRUCTURE_PREVIEW_PICTURE= "structurePictureThumbnail";// 4
    public static final String COLUMN_STRUCTURE_NOTES = "structureNotes";// 4
    
    // Tab 1 Demographic Questionnaire
    public static final String COLUMN_STRUCTURE_CREATED_ON_DATETIME= "createdOnDateTime";// 5
    public static final String COLUMN_STRUCTURE_RECORD_ID= "recordID";// 5
    public static final String COLUMN_STRUCTURE_ENTRY_DESCRIPTOR = "entryDesriptor";
    public static final String COLUMN_STRUCTURE_LOCATION = "location";
    public static final String COLUMN_STRUCTURE_FUNCTION_USAGE_RESIDENCE = "functionUsageResidence";
    public static final String COLUMN_STRUCTURE_FUNCTION_USAGE_MIXED = "functionUsageMixed"; 
    public static final String COLUMN_STRUCTURE_FUNCTION_USAGE_SINGLE = "functionUsageSingle"; 
    public static final String COLUMN_STRUCTURE_FUNCTION_USAGE_MULTIPLE = "functionUsageMultiple"; 
    public static final String COLUMN_STRUCTURE_FUNCTION_USAGE_OTHER = "functionUsageOther"; 
    public static final String COLUMN_STRUCTURE_FUNCTION_USAGE_NOTE = "functionUsageNote";
    public static final String COLUMN_TENANT_ADDRESS= "tenantAddress";// 5
    public static final String COLUMN_TENANT_NAME= "tenantName";// 6
    public static final String COLUMN_TENANT_PHONE_NUMBER= "tenantPhoneNumber";// 7
    public static final String COLUMN_STRUCTURE_OWNERSHIP_STATUS = "ownership";
    public static final String COLUMN_STRUCTURE_OWNERSHIP_STATUS_NOTE = "ownershipNote";
    public static final String COLUMN_STRUCTURE_YEAR_BUILT= "yearBuilt";// 9
    public static final String COLUMN_STRUCTURE_CONSTRUCTION_DURATION= "constructionDuration";
    public static final String COLUMN_STRUCTURE_BUILDER= "builder";// 11
    public static final String COLUMN_STRUCTURE_BUILDER_NOTE= "builderNote";// 11
    public static final String COLUMN_STRUCTURE_NUMBER_OF_ADULTS= "nAdults"; //16
    public static final String COLUMN_STRUCTURE_NUMBER_OF_CHILDREN= "nChildren";// 15

    // Tab 2 Layout Questionnaire
    public static final String COLUMN_STRUCTURE_NUMBER_OF_LEVELS = "nLevels";// 5
    public static final String COLUMN_STRUCTURE_NUMBER_OF_ROOMS = "nRooms";// 5
    public static final String COLUMN_STRUCTURE_PLAN_DIMENSIONS_WIDTH = "structureWidth";// 5
    public static final String COLUMN_STRUCTURE_PLAN_DIMENSIONS_DEPTH = "structureDepth";// 5

    // Tab 3 Primary Questionnaire
    public static final String COLUMN_STRUCTURE_PRIMARY_SYSTEM_CONDITION = "structurePrimarySystemCondition";
    public static final String COLUMN_STRUCTURE_PRIMARY_SYSTEM_CONDITION_NOTE = "structurePrimarySystemConditionNote";
    public static final String COLUMN_STRUCTURE_EXTERIOR_WALL_MATERIAL_MASONRY = "structureExteriorWallMaterialMasonry";
    public static final String COLUMN_STRUCTURE_EXTERIOR_WALL_MATERIAL_STONE = "structureExteriorWallMaterialStone";
    public static final String COLUMN_STRUCTURE_EXTERIOR_WALL_MATERIAL_EARTH = "structureExteriorWallMaterialEarth";
    public static final String COLUMN_STRUCTURE_EXTERIOR_WALL_MATERIAL_WOOD = "structureExteriorWallMaterialWood";
    public static final String COLUMN_STRUCTURE_EXTERIOR_WALL_MATERIAL_METAL = "structureExteriorWallMaterialMetal";
    public static final String COLUMN_STRUCTURE_EXTERIOR_WALL_MATERIAL_OTHER = "structureExteriorWallMaterialOther";
    public static final String COLUMN_STRUCTURE_EXTERIOR_WALL_MATERIAL_NOTE = "structureExteriorWallMaterialNote";
    public static final String COLUMN_STRUCTURE_EXTERIOR_WALL_CONDITION = "structureExteriorWallCondition";
    public static final String COLUMN_STRUCTURE_EXTERIOR_WALL_CONDITION_NOTE = "structureExteriorWallConditionNote";
    public static final String COLUMN_STRUCTURE_EXTERIOR_WALL_THICKNESS = "structureExteriorWallThickness";
    public static final String COLUMN_STRUCTURE_STRUCTURAL_SYSTEM = "structureStructuralSystem";
    public static final String COLUMN_STRUCTURE_STRUCTURAL_SYSTEM_NOTE = "structureStructuralSystemNote";
    public static final String COLUMN_STRUCTURE_LOAD_BEARING_WALL_REINFORCEMENT = "structureLoadBearingReinforcement";
    public static final String COLUMN_STRUCTURE_LOAD_BEARING_WALL_COLUMNS_PRESENT = "structureLoadBearingColumnsPresent";
    public static final String COLUMN_STRUCTURE_LOAD_BEARING_WALL_RING_BEAM = "structureLoadBearingRingBeam";
    		// Column Details
    public static final String COLUMN_STRUCTURE_COLUMN_CONSTRUCTION_MATERIAL_CONCRETE = "structureColumnConstructionMaterialConcrete";
    public static final String COLUMN_STRUCTURE_COLUMN_CONSTRUCTION_MATERIAL_METAL = "structureColumnConstructionMaterialMetal";
    public static final String COLUMN_STRUCTURE_COLUMN_CONSTRUCTION_MATERIAL_WOOD = "structureColumnConstructionMaterialWood";
    public static final String COLUMN_STRUCTURE_COLUMN_CONSTRUCTION_MATERIAL_BAMBOO = "structureColumnConstructionMaterialBamboo";
    public static final String COLUMN_STRUCTURE_COLUMN_CONSTRUCTION_MATERIAL_OTHER = "structureColumnConstructionMaterialOther";
    public static final String COLUMN_STRUCTURE_COLUMN_CONSTRUCTION_MATERIAL_NOTE= "structureColumnConstructionMaterialNote";
    public static final String COLUMN_STRUCTURE_FULL_COLUMN_WIDTH = "structureFullColumnWidth";
    public static final String COLUMN_STRUCTURE_FULL_COLUMN_DEPTH = "structureFullColumnDepth";
    public static final String COLUMN_STRUCTURE_COLUMN_REBAR_CAGE_WIDTH = "structureColumnRebarCageWidth";
    public static final String COLUMN_STRUCTURE_COLUMN_REBAR_CAGE_DEPTH = "structureColumnRebarCageDepth";
    public static final String COLUMN_STRUCTURE_COLUMN_REINFORCEMENT_NUMBER_OF_LONGITUDINAL_BARS = "structureColumnReinforcementNumberOfLongitudinalBars";
    public static final String COLUMN_STRUCTURE_COLUMN_REINFORCEMENT_LONGITUDINAL_BAR_SIZE = "structureColumnReinforcementBarSize";
    public static final String COLUMN_STRUCTURE_COLUMN_REINFORCEMENT_BAR_TEXTURE = "structureColumnReinforcementBarTexture";
    public static final String COLUMN_STRUCTURE_COLUMN_REINFORCEMENT_MINIMUM_TRANSVERSE_SPACING = "structureColumnReinforcementTransverseSpacing";
    public static final String COLUMN_STRUCTURE_COLUMN_REINFORCEMENT_HOOK_DETAIL = "structureColumnReinforcementHookDetail";
    		// Beam Details
    public static final String COLUMN_STRUCTURE_BEAM_CONSTRUCTION_MATERIAL_CONCRETE = "structureBeamConstructionMaterialConcrete";
    public static final String COLUMN_STRUCTURE_BEAM_CONSTRUCTION_MATERIAL_METAL = "structureBeamConstructionMaterialMetal";
    public static final String COLUMN_STRUCTURE_BEAM_CONSTRUCTION_MATERIAL_WOOD = "structureBeamConstructionMaterialWood";
    public static final String COLUMN_STRUCTURE_BEAM_CONSTRUCTION_MATERIAL_BAMBOO = "structureBeamConstructionMaterialBamboo";
    public static final String COLUMN_STRUCTURE_BEAM_CONSTRUCTION_MATERIAL_OTHER = "structureBeamConstructionMaterialOther";
    public static final String COLUMN_STRUCTURE_BEAM_CONSTRUCTION_MATERIAL_NOTE= "structureBeamConstructionMaterialNote";
    public static final String COLUMN_STRUCTURE_FULL_BEAM_WIDTH = "structureFullBeamWidth";
    public static final String COLUMN_STRUCTURE_FULL_BEAM_DEPTH = "structureFullBeamDepth";
    public static final String COLUMN_STRUCTURE_BEAM_REBAR_CAGE_WIDTH = "structureBeamRebarCageWidth";
    public static final String COLUMN_STRUCTURE_BEAM_REBAR_CAGE_DEPTH = "structureBeamRebarCageDepth";
    public static final String COLUMN_STRUCTURE_BEAM_REINFORCEMENT_NUMBER_OF_LONGITUDINAL_BARS = "structureBeamReinforcementNumberOfLongitudinalBars";
    public static final String COLUMN_STRUCTURE_BEAM_REINFORCEMENT_LONGITUDINAL_BAR_SIZE = "structureBeamReinforcementBarSize";
    public static final String COLUMN_STRUCTURE_BEAM_REINFORCEMENT_BAR_TEXTURE = "structureBeamReinforcementBarTexture";
    public static final String COLUMN_STRUCTURE_BEAM_REINFORCEMENT_MINIMUM_TRANSVERSE_SPACING = "structureBeamReinforcementTransverseSpacing";
    public static final String COLUMN_STRUCTURE_BEAM_REINFORCEMENT_HOOK_DETAIL = "structureBeamReinforcementHookDetail";    
           
    // Tab 4 Secondary Questionnaire
    public static final String COLUMN_STRUCTURE_PERMANENT_INTERIOR_PARTITIONS_MASONRY = "structurePermanentInteriorPartitionsMasonry";
    public static final String COLUMN_STRUCTURE_PERMANENT_INTERIOR_PARTITIONS_STONE = "structurePermanentInteriorPartitionsStone";
    public static final String COLUMN_STRUCTURE_PERMANENT_INTERIOR_PARTITIONS_EARTH = "structurePermanentInteriorPartitionsEarth";
    public static final String COLUMN_STRUCTURE_PERMANENT_INTERIOR_PARTITIONS_WOOD = "structurePermanentInteriorPartitionsWood";
    public static final String COLUMN_STRUCTURE_PERMANENT_INTERIOR_PARTITIONS_METAL = "structurePermanentInteriorPartitionsMetal";
    public static final String COLUMN_STRUCTURE_PERMANENT_INTERIOR_PARTITIONS_OTHER = "structurePermanentInteriorPartitionsOther";
    public static final String COLUMN_STRUCTURE_PERMANENT_INTERIOR_PARTITIONS_NOTE = "structurePermanentInteriorPartitionsNote";
    public static final String COLUMN_STRUCTURE_SEMI_PERMANENT_INTERIOR_PARTITIONS_WOOD = "structureSemiPermanentInteriorPartitionsWood";
    public static final String COLUMN_STRUCTURE_SEMI_PERMANENT_INTERIOR_PARTITIONS_CANVAS = "structureSemiPermanentInteriorPartitionsCanvas";
    public static final String COLUMN_STRUCTURE_SEMI_PERMANENT_INTERIOR_PARTITIONS_OTHER = "structureSemiPermanentInteriorPartitionsOther";
    public static final String COLUMN_STRUCTURE_SEMI_PERMANENT_INTERIOR_PARTITIONS_NOTE = "structureSemiPermanentInteriorPartitionsNote";
    		// Foundation System
    public static final String COLUMN_STRUCTURE_FOUNDATION_SYSTEM_NONE = "structureFoundationSystemNone";
    public static final String COLUMN_STRUCTURE_FOUNDATION_SYSTEM_MAT = "structureFoundationSystemMat";
    public static final String COLUMN_STRUCTURE_FOUNDATION_SYSTEM_FOOTINGS = "structureFoundationSystemFootings";
    public static final String COLUMN_STRUCTURE_FOUNDATION_SYSTEM_SHALLOW_FOUNDATION = "structureFoundationSystemShallowFoundation";
    public static final String COLUMN_STRUCTURE_FOUNDATION_SYSTEM_DEEP_FOUNDATION = "structureFoundationSystemDeepFoundation";
    public static final String COLUMN_STRUCTURE_FOUNDATION_SYSTEM_ELEVATED_ON_PILES = "structureFoundationSystemElevatedOnPiles";
    public static final String COLUMN_STRUCTURE_FOUNDATION_SYSTEM_OTHER = "structureFoundationSystemOther";
    public static final String COLUMN_STRUCTURE_FOUNDATION_SYSTEM_NOTE = "structureFoundationSystemNote";
    public static final String COLUMN_STRUCTURE_FOUNDATION_CONSTRUCTION_MATERIAL_NA = "structureFoundationSystemConstructionMaterialNA";
    public static final String COLUMN_STRUCTURE_FOUNDATION_CONSTRUCTION_MATERIAL_MASONRY = "structureFoundationSystemConstructionMaterialMasonry";
    public static final String COLUMN_STRUCTURE_FOUNDATION_CONSTRUCTION_MATERIAL_STONE = "structureFoundationSystemConstructionMaterialStone";
    public static final String COLUMN_STRUCTURE_FOUNDATION_CONSTRUCTION_MATERIAL_CAST_CONCRETE = "structureFoundationSystemConstructionMaterialCastConcrete";
    public static final String COLUMN_STRUCTURE_FOUNDATION_CONSTRUCTION_MATERIAL_WOOD = "structureFoundationSystemConstructionMaterialWood";
    public static final String COLUMN_STRUCTURE_FOUNDATION_CONSTRUCTION_MATERIAL_METAL = "structureFoundationSystemConstructionMaterialMetal";
    public static final String COLUMN_STRUCTURE_FOUNDATION_CONSTRUCTION_MATERIAL_OTHER = "structureFoundationSystemConstructionMaterialOther";
    public static final String COLUMN_STRUCTURE_FOUNDATION_CONSTRUCTION_MATERIAL_NOTE = "structureFoundationSystemConstructionMaterialNote";
    		// Roof System
    public static final String COLUMN_STRUCTURE_ROOF_TYPE_CONCRETE_SLAB = "structureRoofTypeConcreteSlab";
    public static final String COLUMN_STRUCTURE_ROOF_TYPE_FRAMED = "structureRoofTypeFramed";
    public static final String COLUMN_STRUCTURE_ROOF_TYPE_OTHER = "structureRoofTypeOther";
    public static final String COLUMN_STRUCTURE_ROOF_TYPE_NOTE = "structureRoofTypeNote";
    public static final String COLUMN_STRUCTURE_CONCRETE_SLAB_ROOF_PRESENCE_OF_MASONRY = "structureConcreteSlabRoofMasonry";
    public static final String COLUMN_STRUCTURE_FRAMED_ROOF_METAL_FRAMING = "structureFramedRoofMetalFraming";
    public static final String COLUMN_STRUCTURE_FRAMED_ROOF_WOOD_FRAMING = "structureFramedRoofWoodFraming";
    public static final String COLUMN_STRUCTURE_FRAMED_ROOF_METAL_COVERING = "structureFramedRoofMetalCovering";
    public static final String COLUMN_STRUCTURE_FRAMED_ROOF_WOOD_COVERING = "structureFramedRoofWoodCovering";
    public static final String COLUMN_STRUCTURE_FRAMED_ROOF_THATCH_COVERING = "structureFramedRoofThatchCovering";
    public static final String COLUMN_STRUCTURE_FRAMED_ROOF_CANVAS_COVERING = "structureFramedRoofCanvasCovering";
    public static final String COLUMN_STRUCTURE_FRAMED_ROOF_TILES = "structureFramedRoofTiles";
    public static final String COLUMN_STRUCTURE_FRAMED_ROOF_SHINGLES = "structureFramedRoofShingles";
    		// Flooring Construction Material	
    			// Floor 1
    public static final String COLUMN_STRUCTURE_FLOOR_1_CONSTRUCTION_MATERIAL_NA = "structureFloor1ConstructionMaterialNA";
    public static final String COLUMN_STRUCTURE_FLOOR_1_CONSTRUCTION_MATERIAL_MASONRY = "structureFloor1ConstructionMaterialMasonry";
    public static final String COLUMN_STRUCTURE_FLOOR_1_CONSTRUCTION_MATERIAL_STONE = "structureFloor1ConstructionMaterialStone";
    public static final String COLUMN_STRUCTURE_FLOOR_1_CONSTRUCTION_MATERIAL_CAST_CONCRETE = "structureFloor1ConstructionMaterialCastConcrete";
    public static final String COLUMN_STRUCTURE_FLOOR_1_CONSTRUCTION_MATERIAL_WOOD = "structureFloor1ConstructionMaterialWood";
    public static final String COLUMN_STRUCTURE_FLOOR_1_CONSTRUCTION_MATERIAL_METAL = "structureFloor1ConstructionMaterialMetal";
    public static final String COLUMN_STRUCTURE_FLOOR_1_CONSTRUCTION_MATERIAL_OTHER = "structureFloor1ConstructionMaterialOther";
    public static final String COLUMN_STRUCTURE_FLOOR_1_CONSTRUCTION_MATERIAL_NOTE = "structureFloor1ConstructionMaterialNote";
    			// Floor 2
    public static final String COLUMN_STRUCTURE_FLOOR_2_CONSTRUCTION_MATERIAL_NA = "structureFloor2ConstructionMaterialNA";
    public static final String COLUMN_STRUCTURE_FLOOR_2_CONSTRUCTION_MATERIAL_MASONRY = "structureFloor2ConstructionMaterialMasonry";
    public static final String COLUMN_STRUCTURE_FLOOR_2_CONSTRUCTION_MATERIAL_STONE = "structureFloor2ConstructionMaterialStone";
    public static final String COLUMN_STRUCTURE_FLOOR_2_CONSTRUCTION_MATERIAL_CAST_CONCRETE = "structureFloor2ConstructionMaterialCastConcrete";
    public static final String COLUMN_STRUCTURE_FLOOR_2_CONSTRUCTION_MATERIAL_WOOD = "structureFloor2ConstructionMaterialWood";
    public static final String COLUMN_STRUCTURE_FLOOR_2_CONSTRUCTION_MATERIAL_METAL = "structureFloor2ConstructionMaterialMetal";
    public static final String COLUMN_STRUCTURE_FLOOR_2_CONSTRUCTION_MATERIAL_OTHER = "structureFloor2ConstructionMaterialOther";
    public static final String COLUMN_STRUCTURE_FLOOR_2_CONSTRUCTION_MATERIAL_NOTE = "structureFloor2ConstructionMaterialNote";
				 // Floor 3
    public static final String COLUMN_STRUCTURE_FLOOR_3_CONSTRUCTION_MATERIAL_NA = "structureFloor3ConstructionMaterialNA";
    public static final String COLUMN_STRUCTURE_FLOOR_3_CONSTRUCTION_MATERIAL_MASONRY = "structureFloor3ConstructionMaterialMasonry";
    public static final String COLUMN_STRUCTURE_FLOOR_3_CONSTRUCTION_MATERIAL_STONE = "structureFloor3ConstructionMaterialStone";
    public static final String COLUMN_STRUCTURE_FLOOR_3_CONSTRUCTION_MATERIAL_CAST_CONCRETE = "structureFloor3ConstructionMaterialCastConcrete";
    public static final String COLUMN_STRUCTURE_FLOOR_3_CONSTRUCTION_MATERIAL_WOOD = "structureFloor3ConstructionMaterialWood";
    public static final String COLUMN_STRUCTURE_FLOOR_3_CONSTRUCTION_MATERIAL_METAL = "structureFloor3ConstructionMaterialMetal";
    public static final String COLUMN_STRUCTURE_FLOOR_3_CONSTRUCTION_MATERIAL_OTHER = "structureFloor3ConstructionMaterialOther";
    public static final String COLUMN_STRUCTURE_FLOOR_3_CONSTRUCTION_MATERIAL_NOTE = "structureFloor3ConstructionMaterialNote";
    			// Floor 4
    public static final String COLUMN_STRUCTURE_FLOOR_4_CONSTRUCTION_MATERIAL_NA = "structureFloor4ConstructionMaterialNA";
    public static final String COLUMN_STRUCTURE_FLOOR_4_CONSTRUCTION_MATERIAL_MASONRY = "structureFloor4ConstructionMaterialMasonry";
    public static final String COLUMN_STRUCTURE_FLOOR_4_CONSTRUCTION_MATERIAL_STONE = "structureFloor4ConstructionMaterialStone";
    public static final String COLUMN_STRUCTURE_FLOOR_4_CONSTRUCTION_MATERIAL_CAST_CONCRETE = "structureFloor4ConstructionMaterialCastConcrete";
    public static final String COLUMN_STRUCTURE_FLOOR_4_CONSTRUCTION_MATERIAL_WOOD = "structureFloor4ConstructionMaterialWood";
    public static final String COLUMN_STRUCTURE_FLOOR_4_CONSTRUCTION_MATERIAL_METAL = "structureFloor4ConstructionMaterialMetal";
    public static final String COLUMN_STRUCTURE_FLOOR_4_CONSTRUCTION_MATERIAL_OTHER = "structureFloor4ConstructionMaterialOther";
    public static final String COLUMN_STRUCTURE_FLOOR_4_CONSTRUCTION_MATERIAL_NOTE = "structureFloor4ConstructionMaterialNote";
    			// Floor 5
    public static final String COLUMN_STRUCTURE_FLOOR_5_CONSTRUCTION_MATERIAL_NA = "structureFloor5ConstructionMaterialNA";
    public static final String COLUMN_STRUCTURE_FLOOR_5_CONSTRUCTION_MATERIAL_MASONRY = "structureFloor5ConstructionMaterialMasonry";
    public static final String COLUMN_STRUCTURE_FLOOR_5_CONSTRUCTION_MATERIAL_STONE = "structureFloor5ConstructionMaterialStone";
    public static final String COLUMN_STRUCTURE_FLOOR_5_CONSTRUCTION_MATERIAL_CAST_CONCRETE = "structureFloor5ConstructionMaterialCastConcrete";
    public static final String COLUMN_STRUCTURE_FLOOR_5_CONSTRUCTION_MATERIAL_WOOD = "structureFloor5ConstructionMaterialWood";
    public static final String COLUMN_STRUCTURE_FLOOR_5_CONSTRUCTION_MATERIAL_METAL = "structureFloor5ConstructionMaterialMetal";
    public static final String COLUMN_STRUCTURE_FLOOR_5_CONSTRUCTION_MATERIAL_OTHER = "structureFloor5ConstructionMaterialOther";
    public static final String COLUMN_STRUCTURE_FLOOR_5_CONSTRUCTION_MATERIAL_NOTE = "structureFloor5ConstructionMaterialNote";
        
    // Exterior Photos and Observations
    public static final String COLUMN_STRUCTURE_PHOTO_FRONT= "photoFront";
    public static final String COLUMN_STRUCTURE_NOTE_FRONT= "notesFront";
    
    public static final String COLUMN_STRUCTURE_PHOTO_RIGHT= "photoRight";
    public static final String COLUMN_STRUCTURE_NOTE_RIGHT= "notesRight";
    
    public static final String COLUMN_STRUCTURE_PHOTO_BACK= "photoBack";
    public static final String COLUMN_STRUCTURE_NOTE_BACK= "notesBack";
    
    public static final String COLUMN_STRUCTURE_PHOTO_LEFT= "photoLeft";
    public static final String COLUMN_STRUCTURE_NOTE_LEFT= "notesLeft";
    
    // Auxilary Photos
    public static final String COLUMN_STRUCTURE_PHOTO_EXTRA_1= "photoExtra1";
    public static final String COLUMN_STRUCTURE_NOTE_EXTRA_1= "notesExtra1";
    
    public static final String COLUMN_STRUCTURE_PHOTO_EXTRA_2= "photoExtra2";
    public static final String COLUMN_STRUCTURE_NOTE_EXTRA_2= "notesExtra2";
    
    public static final String COLUMN_STRUCTURE_PHOTO_EXTRA_3= "photoExtra3";
    public static final String COLUMN_STRUCTURE_NOTE_EXTRA_3= "notesExtra3";
    
    public static final String COLUMN_STRUCTURE_PHOTO_EXTRA_4= "photoExtra4";
    public static final String COLUMN_STRUCTURE_NOTE_EXTRA_4= "notesExtra4";
    
    public static final String COLUMN_STRUCTURE_PHOTO_EXTRA_5= "photoExtra5";
    public static final String COLUMN_STRUCTURE_NOTE_EXTRA_5= "notesExtra5";
      
    public SQLiteDatabase dbSqlite;
    private Context mContext;

    public SqlHelper(Context context) {
        super(context, DATABASE_NAME, null, 1);
        mContext = context;
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        createDB(db);
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        Log.w("SqlHelper", "Upgrading database from version " + oldVersion
                + " to " + newVersion + ", which will destroy all old data");

        db.execSQL("DROP TABLE IF EXISTS " + TABLE_NAME + ";");
        
        // Add Surveyor Name
//        if (newVersion > oldVersion) {
//            db.execSQL("ALTER TABLE " + TABLE_NAME +" ADD COLUMN surveyorName TEXT");
//        }

        createDB(db);
    }

    public void createDatabase(SQLiteDatabase db) {
        createDB(db);
    }

    private void createDB(SQLiteDatabase db) {
        if (db == null) {
            db = mContext.openOrCreateDatabase(DATABASE_NAME, 0, null);
        }
        
        // REQ:3.5.4.R2  use of a mysql database 
        db.execSQL("CREATE TABLE IF NOT EXISTS "
                + TABLE_NAME + " ("        
                + COLUMN_ID + " INTEGER PRIMARY KEY,"
                + COLUMN_SURVEYOR_NAME + " TEXT DEFAULT \'\' DEFAULT \'\',"
                + COLUMN_STRUCTURE_NAME + " TEXT DEFAULT \'\' DEFAULT \'\',"
                + COLUMN_STRUCTURE_DESC + " TEXT DEFAULT \'\' DEFAULT \'\',"
                + COLUMN_STRUCTURE_STATUS + " TEXT DEFAULT \'\' DEFAULT \'\',"
                + COLUMN_STRUCTURE_PREVIEW_PICTURE + " TEXT DEFAULT \'\' DEFAULT \'\',"
                + COLUMN_STRUCTURE_NOTES + " TEXT DEFAULT \'\' DEFAULT \'\',"	
                + COLUMN_STRUCTURE_CREATED_ON_DATETIME + " DATETIME DEFAULT \'\',"
                + COLUMN_STRUCTURE_RECORD_ID + " INTEGER DEFAULT \'\',"
                + COLUMN_STRUCTURE_ENTRY_DESCRIPTOR + " TEXT DEFAULT \'\',"
                + COLUMN_STRUCTURE_LOCATION + " TEXT DEFAULT \'\',"
                + COLUMN_STRUCTURE_FUNCTION_USAGE_RESIDENCE + " TEXT DEFAULT \'\',"
                + COLUMN_STRUCTURE_FUNCTION_USAGE_MIXED + " TEXT DEFAULT \'\',"
                + COLUMN_STRUCTURE_FUNCTION_USAGE_SINGLE + " TEXT DEFAULT \'\',"
                + COLUMN_STRUCTURE_FUNCTION_USAGE_MULTIPLE + " TEXT DEFAULT \'\',"
                + COLUMN_STRUCTURE_FUNCTION_USAGE_OTHER + " TEXT DEFAULT \'\',"
                + COLUMN_STRUCTURE_FUNCTION_USAGE_NOTE + " TEXT DEFAULT \'\',"
                + COLUMN_TENANT_ADDRESS + " TEXT DEFAULT \'\',"
                + COLUMN_TENANT_NAME + " TEXT DEFAULT \'\',"
                + COLUMN_TENANT_PHONE_NUMBER + " TEXT DEFAULT \'\',"
                + COLUMN_STRUCTURE_OWNERSHIP_STATUS + " TEXT DEFAULT \'\'," 
                + COLUMN_STRUCTURE_OWNERSHIP_STATUS_NOTE + " TEXT DEFAULT \'\'," 
                + COLUMN_STRUCTURE_YEAR_BUILT + " INTEGER DEFAULT \'\',"
                + COLUMN_STRUCTURE_CONSTRUCTION_DURATION + " INTEGER DEFAULT \'\',"
                + COLUMN_STRUCTURE_BUILDER + " TEXT DEFAULT \'\',"
                + COLUMN_STRUCTURE_BUILDER_NOTE + " TEXT DEFAULT \'\',"
                + COLUMN_STRUCTURE_NUMBER_OF_ADULTS + " INTEGER DEFAULT \'\',"
                + COLUMN_STRUCTURE_NUMBER_OF_CHILDREN + " INTEGER DEFAULT \'\',"
                + COLUMN_STRUCTURE_NUMBER_OF_LEVELS + " INTEGER DEFAULT \'\'," 
                + COLUMN_STRUCTURE_NUMBER_OF_ROOMS  + " INTEGER DEFAULT \'\',"
                + COLUMN_STRUCTURE_PLAN_DIMENSIONS_WIDTH + " INTEGER DEFAULT \'\'," 
                + COLUMN_STRUCTURE_PLAN_DIMENSIONS_DEPTH + " TEXT DEFAULT \'\'," 
                + COLUMN_STRUCTURE_PRIMARY_SYSTEM_CONDITION + " TEXT DEFAULT \'\',"
                + COLUMN_STRUCTURE_PRIMARY_SYSTEM_CONDITION_NOTE + " TEXT DEFAULT \'\'," 
                + COLUMN_STRUCTURE_EXTERIOR_WALL_MATERIAL_MASONRY + " TEXT DEFAULT \'\'," 
                + COLUMN_STRUCTURE_EXTERIOR_WALL_MATERIAL_STONE + " TEXT DEFAULT \'\'," 
                + COLUMN_STRUCTURE_EXTERIOR_WALL_MATERIAL_EARTH + " TEXT DEFAULT \'\'," 
                + COLUMN_STRUCTURE_EXTERIOR_WALL_MATERIAL_WOOD + " TEXT DEFAULT \'\'," 
                + COLUMN_STRUCTURE_EXTERIOR_WALL_MATERIAL_METAL + " TEXT DEFAULT \'\'," 
                + COLUMN_STRUCTURE_EXTERIOR_WALL_MATERIAL_OTHER + " TEXT DEFAULT \'\'," 
                + COLUMN_STRUCTURE_EXTERIOR_WALL_MATERIAL_NOTE + " TEXT DEFAULT \'\',"
                + COLUMN_STRUCTURE_EXTERIOR_WALL_CONDITION + " TEXT DEFAULT \'\'," 
                + COLUMN_STRUCTURE_EXTERIOR_WALL_CONDITION_NOTE + " TEXT DEFAULT \'\',"
                + COLUMN_STRUCTURE_EXTERIOR_WALL_THICKNESS + " INTEGER DEFAULT \'\'," 
                + COLUMN_STRUCTURE_STRUCTURAL_SYSTEM + " TEXT DEFAULT \'\'," 
                + COLUMN_STRUCTURE_STRUCTURAL_SYSTEM_NOTE + " TEXT DEFAULT \'\',"
                + COLUMN_STRUCTURE_LOAD_BEARING_WALL_REINFORCEMENT + " INTEGER DEFAULT \'\'," 
                + COLUMN_STRUCTURE_LOAD_BEARING_WALL_COLUMNS_PRESENT + " INTEGER DEFAULT \'\'," 
                + COLUMN_STRUCTURE_LOAD_BEARING_WALL_RING_BEAM + " INTEGER DEFAULT \'\'," 
                + COLUMN_STRUCTURE_COLUMN_CONSTRUCTION_MATERIAL_CONCRETE + " TEXT DEFAULT \'\',"
                + COLUMN_STRUCTURE_COLUMN_CONSTRUCTION_MATERIAL_METAL + " TEXT DEFAULT \'\'," 
                + COLUMN_STRUCTURE_COLUMN_CONSTRUCTION_MATERIAL_WOOD + " TEXT DEFAULT \'\'," 
                + COLUMN_STRUCTURE_COLUMN_CONSTRUCTION_MATERIAL_BAMBOO + " TEXT DEFAULT \'\',"
                + COLUMN_STRUCTURE_COLUMN_CONSTRUCTION_MATERIAL_OTHER + " TEXT DEFAULT \'\'," 
                + COLUMN_STRUCTURE_COLUMN_CONSTRUCTION_MATERIAL_NOTE + " TEXT DEFAULT \'\',"
                + COLUMN_STRUCTURE_FULL_COLUMN_WIDTH + " INTEGER DEFAULT \'\'," 
                + COLUMN_STRUCTURE_FULL_COLUMN_DEPTH + " INTEGER DEFAULT \'\'," 
                + COLUMN_STRUCTURE_COLUMN_REBAR_CAGE_WIDTH + " INTEGER DEFAULT \'\',"
                + COLUMN_STRUCTURE_COLUMN_REBAR_CAGE_DEPTH + " INTEGER DEFAULT \'\',"
                + COLUMN_STRUCTURE_COLUMN_REINFORCEMENT_NUMBER_OF_LONGITUDINAL_BARS + " INTEGER DEFAULT \'\'," 
                + COLUMN_STRUCTURE_COLUMN_REINFORCEMENT_LONGITUDINAL_BAR_SIZE + " INTEGER DEFAULT \'\',"
                + COLUMN_STRUCTURE_COLUMN_REINFORCEMENT_BAR_TEXTURE + " TEXT DEFAULT \'\'," 
                + COLUMN_STRUCTURE_COLUMN_REINFORCEMENT_MINIMUM_TRANSVERSE_SPACING + " INTEGER DEFAULT \'\',"
                + COLUMN_STRUCTURE_COLUMN_REINFORCEMENT_HOOK_DETAIL + " TEXT DEFAULT \'\'," 
                + COLUMN_STRUCTURE_BEAM_CONSTRUCTION_MATERIAL_CONCRETE + " TEXT DEFAULT \'\',"
                + COLUMN_STRUCTURE_BEAM_CONSTRUCTION_MATERIAL_METAL + " TEXT DEFAULT \'\'," 
                + COLUMN_STRUCTURE_BEAM_CONSTRUCTION_MATERIAL_WOOD + " TEXT DEFAULT \'\'," 
                + COLUMN_STRUCTURE_BEAM_CONSTRUCTION_MATERIAL_BAMBOO + " TEXT DEFAULT \'\'," 
                + COLUMN_STRUCTURE_BEAM_CONSTRUCTION_MATERIAL_OTHER + " TEXT DEFAULT \'\'," 
                + COLUMN_STRUCTURE_BEAM_CONSTRUCTION_MATERIAL_NOTE + " TEXT DEFAULT \'\',"
                + COLUMN_STRUCTURE_FULL_BEAM_WIDTH + " INTEGER DEFAULT \'\'," 
                + COLUMN_STRUCTURE_FULL_BEAM_DEPTH + " INTEGER DEFAULT \'\'," 
                + COLUMN_STRUCTURE_BEAM_REBAR_CAGE_WIDTH + " INTEGER DEFAULT \'\'," 
                + COLUMN_STRUCTURE_BEAM_REBAR_CAGE_DEPTH + " INTEGER DEFAULT \'\'," 
                + COLUMN_STRUCTURE_BEAM_REINFORCEMENT_NUMBER_OF_LONGITUDINAL_BARS + " INTEGER DEFAULT \'\'," 
                + COLUMN_STRUCTURE_BEAM_REINFORCEMENT_LONGITUDINAL_BAR_SIZE + " INTEGER DEFAULT \'\'," 
                + COLUMN_STRUCTURE_BEAM_REINFORCEMENT_BAR_TEXTURE + " TEXT DEFAULT \'\',"
                + COLUMN_STRUCTURE_BEAM_REINFORCEMENT_MINIMUM_TRANSVERSE_SPACING + " INTEGER DEFAULT \'\',"
                + COLUMN_STRUCTURE_BEAM_REINFORCEMENT_HOOK_DETAIL + " TEXT DEFAULT \'\',"    
                + COLUMN_STRUCTURE_PERMANENT_INTERIOR_PARTITIONS_MASONRY + " TEXT DEFAULT \'\'," 
                + COLUMN_STRUCTURE_PERMANENT_INTERIOR_PARTITIONS_STONE + " TEXT DEFAULT \'\'," 
                + COLUMN_STRUCTURE_PERMANENT_INTERIOR_PARTITIONS_EARTH + " TEXT DEFAULT \'\'," 
                + COLUMN_STRUCTURE_PERMANENT_INTERIOR_PARTITIONS_WOOD + " TEXT DEFAULT \'\'," 
                + COLUMN_STRUCTURE_PERMANENT_INTERIOR_PARTITIONS_METAL + " TEXT DEFAULT \'\',"
                + COLUMN_STRUCTURE_PERMANENT_INTERIOR_PARTITIONS_OTHER + " TEXT DEFAULT \'\',"
                + COLUMN_STRUCTURE_PERMANENT_INTERIOR_PARTITIONS_NOTE + " TEXT DEFAULT \'\'," 
                + COLUMN_STRUCTURE_SEMI_PERMANENT_INTERIOR_PARTITIONS_WOOD + " TEXT DEFAULT \'\',"
                + COLUMN_STRUCTURE_SEMI_PERMANENT_INTERIOR_PARTITIONS_CANVAS + " TEXT DEFAULT \'\',"
                + COLUMN_STRUCTURE_SEMI_PERMANENT_INTERIOR_PARTITIONS_OTHER + " TEXT DEFAULT \'\',"
                + COLUMN_STRUCTURE_SEMI_PERMANENT_INTERIOR_PARTITIONS_NOTE + " TEXT DEFAULT \'\',"
                + COLUMN_STRUCTURE_FOUNDATION_SYSTEM_NONE + " TEXT DEFAULT \'\',"
                + COLUMN_STRUCTURE_FOUNDATION_SYSTEM_MAT + " TEXT DEFAULT \'\',"
                + COLUMN_STRUCTURE_FOUNDATION_SYSTEM_FOOTINGS + " TEXT DEFAULT \'\',"
                + COLUMN_STRUCTURE_FOUNDATION_SYSTEM_SHALLOW_FOUNDATION + " TEXT DEFAULT \'\',"
                + COLUMN_STRUCTURE_FOUNDATION_SYSTEM_DEEP_FOUNDATION  + " TEXT DEFAULT \'\',"
                + COLUMN_STRUCTURE_FOUNDATION_SYSTEM_ELEVATED_ON_PILES  + " TEXT DEFAULT \'\',"
                + COLUMN_STRUCTURE_FOUNDATION_SYSTEM_OTHER + " TEXT DEFAULT \'\'," 
                + COLUMN_STRUCTURE_FOUNDATION_SYSTEM_NOTE + " TEXT DEFAULT \'\'," 
                + COLUMN_STRUCTURE_FOUNDATION_CONSTRUCTION_MATERIAL_NA + " TEXT DEFAULT \'\'," 
                + COLUMN_STRUCTURE_FOUNDATION_CONSTRUCTION_MATERIAL_MASONRY + " TEXT DEFAULT \'\',"
                + COLUMN_STRUCTURE_FOUNDATION_CONSTRUCTION_MATERIAL_STONE + " TEXT DEFAULT \'\',"
                + COLUMN_STRUCTURE_FOUNDATION_CONSTRUCTION_MATERIAL_CAST_CONCRETE + " TEXT DEFAULT \'\',"
                + COLUMN_STRUCTURE_FOUNDATION_CONSTRUCTION_MATERIAL_WOOD + " TEXT DEFAULT \'\',"
                + COLUMN_STRUCTURE_FOUNDATION_CONSTRUCTION_MATERIAL_METAL + " TEXT DEFAULT \'\',"
                + COLUMN_STRUCTURE_FOUNDATION_CONSTRUCTION_MATERIAL_OTHER + " TEXT DEFAULT \'\',"
                + COLUMN_STRUCTURE_FOUNDATION_CONSTRUCTION_MATERIAL_NOTE + " TEXT DEFAULT \'\',"
                + COLUMN_STRUCTURE_ROOF_TYPE_CONCRETE_SLAB + " TEXT DEFAULT \'\',"
                + COLUMN_STRUCTURE_ROOF_TYPE_FRAMED + " TEXT DEFAULT \'\',"
                + COLUMN_STRUCTURE_ROOF_TYPE_OTHER + " TEXT DEFAULT \'\',"
                + COLUMN_STRUCTURE_ROOF_TYPE_NOTE + " TEXT DEFAULT \'\',"
                + COLUMN_STRUCTURE_CONCRETE_SLAB_ROOF_PRESENCE_OF_MASONRY + " TEXT DEFAULT \'\',"
                + COLUMN_STRUCTURE_FRAMED_ROOF_METAL_FRAMING + " TEXT DEFAULT \'\',"
                + COLUMN_STRUCTURE_FRAMED_ROOF_WOOD_FRAMING + " TEXT DEFAULT \'\'," 
                + COLUMN_STRUCTURE_FRAMED_ROOF_METAL_COVERING + " TEXT DEFAULT \'\',"
                + COLUMN_STRUCTURE_FRAMED_ROOF_WOOD_COVERING + " TEXT DEFAULT \'\',"
                + COLUMN_STRUCTURE_FRAMED_ROOF_THATCH_COVERING + " TEXT DEFAULT \'\',"
                + COLUMN_STRUCTURE_FRAMED_ROOF_CANVAS_COVERING + " TEXT DEFAULT \'\',"
                + COLUMN_STRUCTURE_FRAMED_ROOF_TILES + " TEXT DEFAULT \'\',"
                + COLUMN_STRUCTURE_FRAMED_ROOF_SHINGLES + " TEXT DEFAULT \'\',"
                + COLUMN_STRUCTURE_FLOOR_1_CONSTRUCTION_MATERIAL_NA + " TEXT DEFAULT \'\'," 
                + COLUMN_STRUCTURE_FLOOR_1_CONSTRUCTION_MATERIAL_MASONRY + " TEXT DEFAULT \'\'," 
                + COLUMN_STRUCTURE_FLOOR_1_CONSTRUCTION_MATERIAL_STONE + " TEXT DEFAULT \'\'," 
                + COLUMN_STRUCTURE_FLOOR_1_CONSTRUCTION_MATERIAL_CAST_CONCRETE + " TEXT DEFAULT \'\'," 
                + COLUMN_STRUCTURE_FLOOR_1_CONSTRUCTION_MATERIAL_WOOD + " TEXT DEFAULT \'\'," 
                + COLUMN_STRUCTURE_FLOOR_1_CONSTRUCTION_MATERIAL_METAL + " TEXT DEFAULT \'\',"
                + COLUMN_STRUCTURE_FLOOR_1_CONSTRUCTION_MATERIAL_OTHER + " TEXT DEFAULT \'\',"
                + COLUMN_STRUCTURE_FLOOR_1_CONSTRUCTION_MATERIAL_NOTE + " TEXT DEFAULT \'\',"
                + COLUMN_STRUCTURE_FLOOR_2_CONSTRUCTION_MATERIAL_NA + " TEXT DEFAULT \'\',"
                + COLUMN_STRUCTURE_FLOOR_2_CONSTRUCTION_MATERIAL_MASONRY + " TEXT DEFAULT \'\',"
                + COLUMN_STRUCTURE_FLOOR_2_CONSTRUCTION_MATERIAL_STONE + " TEXT DEFAULT \'\',"
                + COLUMN_STRUCTURE_FLOOR_2_CONSTRUCTION_MATERIAL_CAST_CONCRETE + " TEXT DEFAULT \'\',"
                + COLUMN_STRUCTURE_FLOOR_2_CONSTRUCTION_MATERIAL_WOOD + " TEXT DEFAULT \'\',"
                + COLUMN_STRUCTURE_FLOOR_2_CONSTRUCTION_MATERIAL_METAL + " TEXT DEFAULT \'\',"
                + COLUMN_STRUCTURE_FLOOR_2_CONSTRUCTION_MATERIAL_OTHER + " TEXT DEFAULT \'\',"
                + COLUMN_STRUCTURE_FLOOR_2_CONSTRUCTION_MATERIAL_NOTE + " TEXT DEFAULT \'\',"
                + COLUMN_STRUCTURE_FLOOR_3_CONSTRUCTION_MATERIAL_NA + " TEXT DEFAULT \'\',"
                + COLUMN_STRUCTURE_FLOOR_3_CONSTRUCTION_MATERIAL_MASONRY + " TEXT DEFAULT \'\',"
                + COLUMN_STRUCTURE_FLOOR_3_CONSTRUCTION_MATERIAL_STONE + " TEXT DEFAULT \'\',"
                + COLUMN_STRUCTURE_FLOOR_3_CONSTRUCTION_MATERIAL_CAST_CONCRETE + " TEXT DEFAULT \'\',"
                + COLUMN_STRUCTURE_FLOOR_3_CONSTRUCTION_MATERIAL_WOOD + " TEXT DEFAULT \'\',"
                + COLUMN_STRUCTURE_FLOOR_3_CONSTRUCTION_MATERIAL_METAL + " TEXT DEFAULT \'\',"
                + COLUMN_STRUCTURE_FLOOR_3_CONSTRUCTION_MATERIAL_OTHER + " TEXT DEFAULT \'\',"
                + COLUMN_STRUCTURE_FLOOR_3_CONSTRUCTION_MATERIAL_NOTE + " TEXT DEFAULT \'\',"
                + COLUMN_STRUCTURE_FLOOR_4_CONSTRUCTION_MATERIAL_NA + " TEXT DEFAULT \'\',"
                + COLUMN_STRUCTURE_FLOOR_4_CONSTRUCTION_MATERIAL_MASONRY + " TEXT DEFAULT \'\',"
                + COLUMN_STRUCTURE_FLOOR_4_CONSTRUCTION_MATERIAL_STONE + " TEXT DEFAULT \'\',"
                + COLUMN_STRUCTURE_FLOOR_4_CONSTRUCTION_MATERIAL_CAST_CONCRETE + " TEXT DEFAULT \'\',"
                + COLUMN_STRUCTURE_FLOOR_4_CONSTRUCTION_MATERIAL_WOOD + " TEXT DEFAULT \'\',"
                + COLUMN_STRUCTURE_FLOOR_4_CONSTRUCTION_MATERIAL_METAL + " TEXT DEFAULT \'\',"
                + COLUMN_STRUCTURE_FLOOR_4_CONSTRUCTION_MATERIAL_OTHER + " TEXT DEFAULT \'\',"
                + COLUMN_STRUCTURE_FLOOR_4_CONSTRUCTION_MATERIAL_NOTE + " TEXT DEFAULT \'\',"
                + COLUMN_STRUCTURE_FLOOR_5_CONSTRUCTION_MATERIAL_NA + " TEXT DEFAULT \'\'," 
                + COLUMN_STRUCTURE_FLOOR_5_CONSTRUCTION_MATERIAL_MASONRY + " TEXT DEFAULT \'\',"
                + COLUMN_STRUCTURE_FLOOR_5_CONSTRUCTION_MATERIAL_STONE + " TEXT DEFAULT \'\',"
                + COLUMN_STRUCTURE_FLOOR_5_CONSTRUCTION_MATERIAL_CAST_CONCRETE + " TEXT DEFAULT \'\',"
                + COLUMN_STRUCTURE_FLOOR_5_CONSTRUCTION_MATERIAL_WOOD + " TEXT DEFAULT \'\'," 
                + COLUMN_STRUCTURE_FLOOR_5_CONSTRUCTION_MATERIAL_METAL + " TEXT DEFAULT \'\',"
                + COLUMN_STRUCTURE_FLOOR_5_CONSTRUCTION_MATERIAL_OTHER + " TEXT DEFAULT \'\',"
                + COLUMN_STRUCTURE_FLOOR_5_CONSTRUCTION_MATERIAL_NOTE + " TEXT DEFAULT \'\',"
                + COLUMN_STRUCTURE_PHOTO_FRONT + " TEXT DEFAULT \'\',"
                + COLUMN_STRUCTURE_NOTE_FRONT + " TEXT DEFAULT \'\',"
                + COLUMN_STRUCTURE_PHOTO_RIGHT + " TEXT DEFAULT \'\',"
                + COLUMN_STRUCTURE_NOTE_RIGHT + " TEXT DEFAULT \'\',"
                + COLUMN_STRUCTURE_PHOTO_BACK + " TEXT DEFAULT \'\',"
                + COLUMN_STRUCTURE_NOTE_BACK + " TEXT DEFAULT \'\',"
                + COLUMN_STRUCTURE_PHOTO_LEFT + " TEXT DEFAULT \'\',"
                + COLUMN_STRUCTURE_NOTE_LEFT + " TEXT DEFAULT \'\',"
                + COLUMN_STRUCTURE_PHOTO_EXTRA_1 + " TEXT DEFAULT \'\',"
                + COLUMN_STRUCTURE_NOTE_EXTRA_1 + " TEXT DEFAULT \'\',"
                + COLUMN_STRUCTURE_PHOTO_EXTRA_2 + " TEXT DEFAULT \'\',"
                + COLUMN_STRUCTURE_NOTE_EXTRA_2 + " TEXT DEFAULT \'\',"
                + COLUMN_STRUCTURE_PHOTO_EXTRA_3 + " TEXT DEFAULT \'\',"
                + COLUMN_STRUCTURE_NOTE_EXTRA_3 + " TEXT DEFAULT \'\',"
                + COLUMN_STRUCTURE_PHOTO_EXTRA_4 + " TEXT DEFAULT \'\',"
                + COLUMN_STRUCTURE_NOTE_EXTRA_4 + " TEXT DEFAULT \'\',"
                + COLUMN_STRUCTURE_PHOTO_EXTRA_5 + " TEXT DEFAULT \'\',"
                + COLUMN_STRUCTURE_NOTE_EXTRA_5 + " TEXT DEFAULT \'\'"
                + ");");

        db.setVersion(StructureItems_VERSION);
    }

    public void openDataBase() throws SQLException {
        String myPath = DATABASE_PATH + DATABASE_NAME;
        
        dbSqlite = SQLiteDatabase.openDatabase(myPath, null,
                SQLiteDatabase.OPEN_READWRITE);
    }

    @Override
    public synchronized void close() {
        if (dbSqlite != null)
            dbSqlite.close();
        super.close();
    }

    public Cursor getCursor(String selection) {
        SQLiteQueryBuilder queryBuilder = new SQLiteQueryBuilder();

        queryBuilder.setTables(TABLE_NAME);
        
        // returns all columns, 
        // change the first null value to an array of column names to only return certain columns
        Cursor mCursor = queryBuilder.query(dbSqlite, null, selection,
                null, null, null, COLUMN_STRUCTURE_STATUS +" ASC");

        return mCursor;
    } 
    
    public int getStructureID(Cursor currentCursor){
    	
    	int structureID = currentCursor.getInt(currentCursor.getColumnIndex(COLUMN_ID)); 
    	   	
    	return structureID;
    }
     
    public void delete_byID(int id){
    	dbSqlite.delete(TABLE_NAME, COLUMN_ID+"="+id, null);
    	}
    
    public void createStructureEntry(String structureName, String structureDesc) {
        SQLiteDatabase db = this.getWritableDatabase();

        // Get Current Date/Time
        String DATEFORMAT = "yyyy-MM-dd HH:mm:ss";
        
        SimpleDateFormat sdf = new SimpleDateFormat(DATEFORMAT);
        sdf.setTimeZone(TimeZone.getTimeZone("GMT"));
        String currentDateTime = sdf.format(new Date());

        // Generate Record ID
        String DATEFORMAT2 = "yyyy:MM:dd:HH:mm";
        
        SimpleDateFormat sdf2 = new SimpleDateFormat(DATEFORMAT2);
        sdf2.setTimeZone(TimeZone.getTimeZone("GMT"));
        String recordID = sdf2.format(new Date());     
        
        ContentValues initial = new ContentValues();
        
        // Creates the new structure entry with Name Desc, and Status
        initial.put(COLUMN_STRUCTURE_NAME, structureName);
        initial.put(COLUMN_STRUCTURE_DESC, structureDesc);
        initial.put(COLUMN_STRUCTURE_STATUS, "New");
        initial.put(COLUMN_STRUCTURE_CREATED_ON_DATETIME, currentDateTime);
        initial.put(COLUMN_STRUCTURE_RECORD_ID, recordID);
        
        db.insert(TABLE_NAME, null, initial);
                
    }  
    
    public void updateStructureEntry(String[][] databaseUpdates, int structureID) {
        ContentValues values = new ContentValues();
        	
        // Creates 2xn array that stores the field name and field value that are to be updated
        for (int i=0 ; i<databaseUpdates.length; i++){
        	values.put(databaseUpdates[i][0], databaseUpdates[i][1]);		
        }
                           
       dbSqlite.update(SqlHelper.TABLE_NAME, values, COLUMN_ID  + "=" + structureID, null);
    }

}